home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decodemsvc.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  14KB  |  439 lines

  1. /*
  2. sc:c/sc opt txt/DecodeMSVC.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "Utils.h"
  7. #include "YUV.h"
  8. #include "GlobalVars.h"
  9.  
  10. struct MSVCData {
  11.   ulong dummy;
  12. };
  13.  
  14. /* /// "blockInc" */
  15. #define blockInc(x,y,xmax) { \
  16.                       x+=4; \
  17.                       if (x>=xmax) { \
  18.                         x=0; \
  19.                         y-=4; \
  20.                       } \
  21.                    }
  22. /* \\\ */
  23.  
  24. /* /// "cram8c#" */
  25. #define cram8c1(ip,clr,rdec) { \
  26.   ip[0]=ip[1]=ip[2]=ip[3]=clr; ip-=rowDec; \
  27.   ip[0]=ip[1]=ip[2]=ip[3]=clr; ip-=rowDec; \
  28.   ip[0]=ip[1]=ip[2]=ip[3]=clr; ip-=rowDec; \
  29.   ip[0]=ip[1]=ip[2]=ip[3]=clr;             \
  30. /* \
  31.   *ip=clr; ip=(ulong *)((ulong)ip-rdec); \
  32.   *ip=clr; ip=(ulong *)((ulong)ip-rdec); \
  33.   *ip=clr; ip=(ulong *)((ulong)ip-rdec); \
  34.   *ip=clr; \
  35. */ \
  36. }
  37.  
  38. #define cram8c2(ip,flag,cA,cB,rowDec) { \
  39.   ip[0]=(flag & 0x01) ? (cB) : (cA);    \
  40.   ip[1]=(flag & 0x02) ? (cB) : (cA);    \
  41.   ip[2]=(flag & 0x04) ? (cB) : (cA);    \
  42.   ip[3]=(flag & 0x08) ? (cB) : (cA);    \
  43.   ip-=rowDec;                           \
  44.   ip[0]=(flag & 0x10) ? (cB) : (cA);    \
  45.   ip[1]=(flag & 0x20) ? (cB) : (cA);    \
  46.   ip[2]=(flag & 0x40) ? (cB) : (cA);    \
  47.   ip[3]=(flag & 0x80) ? (cB) : (cA);    \
  48. }
  49.  
  50. #define cram8c4(ip,flag,cA0,cA1,cB0,cB1,rowDec) { \
  51.   ip[0]=(flag & 0x01) ? (cB0) : (cA0);            \
  52.   ip[1]=(flag & 0x02) ? (cB0) : (cA0);            \
  53.   ip[2]=(flag & 0x04) ? (cB1) : (cA1);            \
  54.   ip[3]=(flag & 0x08) ? (cB1) : (cA1);            \
  55.   ip-=rowDec;                                     \
  56.   ip[0]=(flag & 0x10) ? (cB0) : (cA0);            \
  57.   ip[1]=(flag & 0x20) ? (cB0) : (cA0);            \
  58.   ip[2]=(flag & 0x40) ? (cB1) : (cA1);            \
  59.   ip[3]=(flag & 0x80) ? (cB1) : (cA1);            \
  60. }
  61. /* \\\ */
  62.  
  63. /* /// "DecodeMSVC8to332()" */
  64. __asm void DecodeMSVC8to332(REG(a0) uchar *from,
  65.                             REG(a1) uchar *to,
  66.                             REG(d0) ulong width,
  67.                             REG(d1) ulong height,
  68.                             REG(d2) ulong encSize,
  69.                             REG(a2) struct MSVCData *spec)
  70. {
  71.   long exitflag=0;
  72.   ulong code0;
  73.   ulong code1;
  74.   ulong blockCnt=((width*height)>>4)+1;
  75.   long xp=0;
  76.   long yp=height-1;
  77.   ulong rowDec=width;
  78.  
  79.   while(!exitflag) {
  80.     code0=from[0];
  81.     code1=from[1];
  82.     from+=2;
  83.     blockCnt--;
  84.     if (((code1==0) && (code0==0) && !blockCnt) || (yp<0))
  85.       exitflag=1;
  86.     else {
  87.       if ((code1>=0x84) && (code1<=0x87)) {
  88.         ulong skip=((code1-0x84)<<8)+code0;
  89.         blockCnt-=(skip-1);
  90.         while(skip--) blockInc(xp,yp,rowDec);
  91.       } else {
  92.         uchar *iptr=(to+yp*width+xp);
  93.         if (code1>=0x90) {
  94.           uchar cA0,cA1,cB0,cB1;
  95.           cB0=remap[from[0]];
  96.           cA0=remap[from[1]];
  97.           cB1=remap[from[2]];
  98.           cA1=remap[from[3]];
  99.           cram8c4(iptr,code0,cA0,cA1,cB0,cB1,rowDec); iptr-=rowDec;
  100.           cB0=remap[from[4]];
  101.           cA0=remap[from[5]];
  102.           cB1=remap[from[6]];
  103.           cA1=remap[from[7]];
  104.           cram8c4(iptr,code1,cA0,cA1,cB0,cB1,rowDec);
  105.           from+=8;
  106.         } else if (code1<0x80) {
  107.           uchar cA,cB;
  108.           cB=remap[from[0]];
  109.           cA=remap[from[1]];
  110.           from+=2;
  111.           cram8c2(iptr,code0,cA,cB,rowDec); iptr-=rowDec;
  112.           cram8c2(iptr,code1,cA,cB,rowDec);
  113.         } else {
  114.           code0=remap[code0];
  115.           cram8c1(iptr,code0,rowDec);
  116.         }
  117.         blockInc(xp,yp,rowDec);
  118.       }
  119.     }
  120.   }
  121. }
  122. /* \\\ */
  123.  
  124. /* /// "DecodeMSVC8toRGB()" */
  125. __asm void DecodeMSVC8toRGB(REG(a0) uchar *from,
  126.                             REG(a1) uchar *to,
  127.                             REG(d0) ulong width,
  128.                             REG(d1) ulong height,
  129.                             REG(d2) ulong encSize,
  130.                             REG(a2) struct MSVCData *spec)
  131. {
  132.   long exitflag=0;
  133.   ulong code0;
  134.   ulong code1;
  135.   ulong blockCnt=((width*height)>>4)+1;
  136.   long xp=0;
  137.   long yp=height-1;
  138.   ulong rowDec=width;
  139.  
  140.   while(!exitflag) {
  141.     code0=from[0];
  142.     code1=from[1];
  143.     from+=2;
  144.     blockCnt--;
  145.     if (((code1==0) && (code0==0) && !blockCnt) || (yp<0))
  146.       exitflag=1;
  147.     else {
  148.       if ((code1>=0x84) && (code1<=0x87)) {
  149.         ulong skip=((code1-0x84)<<8)+code0;
  150.         blockCnt-=(skip-1);
  151.         while(skip--) blockInc(xp,yp,rowDec);
  152.       } else {
  153.         RGBTriple *iptr=(RGBTriple *)(to+(yp*width+xp)*4);
  154.         if (code1>=0x90) {
  155.           RGBTriple clrA0, clrA1, clrB0, clrB1;
  156.           clrA0.alpha=0;
  157.           clrA1.alpha=0;
  158.           clrB0.alpha=0;
  159.           clrB1.alpha=0;
  160.           Idx332ToRGB(from[0],clrB0.red,clrB0.green,clrB0.blue);
  161.           Idx332ToRGB(from[1],clrA0.red,clrA0.green,clrA0.blue);
  162.           Idx332ToRGB(from[2],clrB1.red,clrB1.green,clrB1.blue);
  163.           Idx332ToRGB(from[3],clrA1.red,clrA1.green,clrA1.blue);
  164.           cram8c4(iptr,code0,clrA0,clrA1,clrB0,clrB1,rowDec); iptr-=rowDec;
  165.           Idx332ToRGB(from[4],clrB0.red,clrB0.green,clrB0.blue);
  166.           Idx332ToRGB(from[5],clrA0.red,clrA0.green,clrA0.blue);
  167.           Idx332ToRGB(from[6],clrB1.red,clrB1.green,clrB1.blue);
  168.           Idx332ToRGB(from[7],clrA1.red,clrA1.green,clrA1.blue);
  169.           cram8c4(iptr,code1,clrA0,clrA1,clrB0,clrB1,rowDec);
  170.           from+=8;
  171.         } else if (code1<0x80) {
  172.           RGBTriple clrA, clrB;
  173.           clrA.alpha=0;
  174.           clrB.alpha=0;
  175.           Idx332ToRGB(from[0],clrB.red,clrB.green,clrB.blue);
  176.           Idx332ToRGB(from[1],clrA.red,clrA.green,clrA.blue);
  177.           cram8c2(iptr,code0,clrA,clrB,rowDec); iptr-=rowDec;
  178.           cram8c2(iptr,code1,clrA,clrB,rowDec);
  179.           from+=2;
  180.         } else {
  181.           RGBTriple clr;
  182.           clr.alpha=0;
  183.           Idx332ToRGB(code0,clr.red,clr.green,clr.blue);
  184.           cram8c1(iptr,clr,rowDec);
  185.         }
  186.         blockInc(xp,yp,rowDec);
  187.       }
  188.     }
  189.   }
  190. }
  191. /* \\\ */
  192.  
  193. /* /// "DecodeMSVC16toRGB()" */
  194. __asm void DecodeMSVC16toRGB(REG(a0) uchar *from,
  195.                              REG(a1) uchar *to,
  196.                              REG(d0) ulong width,
  197.                              REG(d1) ulong height,
  198.                              REG(d2) ulong encSize,
  199.                              REG(a2) struct MSVCData *spec)
  200. {
  201.   long exitflag=0;
  202.   ulong code0;
  203.   ulong code1;
  204.   ulong blockCnt=((width*height)>>4)+1;
  205.   long xp=0;
  206.   long yp=height-1;
  207.   ulong rowDec=width;
  208.  
  209.   while(!exitflag) {
  210.     code0=*from++;
  211.     code1=*from++;
  212.     blockCnt--;
  213.     if (((code1==0) && (code0==0) && !blockCnt) || (yp<0)) {
  214.       exitflag=1;
  215.       continue;
  216.     }
  217.     if ((code1>=0x84) && (code1<=0x87)) {
  218.       ulong skip=((code1-0x84)<<8)+code0;
  219.       blockCnt-=(skip-1);
  220.       while(skip--) blockInc(xp,yp,rowDec);
  221.     } else {
  222.       RGBTriple *iptr=(RGBTriple *)(to+(yp*width+xp)*4);
  223.       if (code1<0x80) {
  224.         ulong cA, cB;
  225.         RGBTriple clrA0, clrB0;
  226.         cB=get16pc(from);
  227.         cA=get16pc(from);
  228.         clrA0.alpha=0;
  229.         clrB0.alpha=0;
  230.         RGB16toRGB24(cA,clrA0.red,clrA0.green,clrA0.blue);
  231.         RGB16toRGB24(cB,clrB0.red,clrB0.green,clrB0.blue);
  232.         if (cB & 0x8000) {
  233.           RGBTriple clrA1, clrB1;
  234.           cB=get16pc(from);
  235.           cA=get16pc(from);
  236.           clrA1.alpha=0;
  237.           clrB1.alpha=0;
  238.           RGB16toRGB24(cA,clrA1.red,clrA1.green,clrA1.blue);
  239.           RGB16toRGB24(cB,clrB1.red,clrB1.green,clrB1.blue);
  240.           cram8c4(iptr,code0,clrA0,clrA1,clrB0,clrB1,rowDec); iptr-=rowDec;
  241.           cB=get16pc(from);
  242.           cA=get16pc(from);
  243.           RGB16toRGB24(cA,clrA0.red,clrA0.green,clrA0.blue);
  244.           RGB16toRGB24(cB,clrB0.red,clrB0.green,clrB0.blue);
  245.           cB=get16pc(from);
  246.           cA=get16pc(from);
  247.           RGB16toRGB24(cA,clrA1.red,clrA1.green,clrA1.blue);
  248.           RGB16toRGB24(cB,clrB1.red,clrB1.green,clrB1.blue);
  249.           cram8c4(iptr,code1,clrA0,clrA1,clrB0,clrB1,rowDec);
  250.         } else {
  251.           cram8c2(iptr,code0,clrA0,clrB0,rowDec); iptr-=rowDec;
  252.           cram8c2(iptr,code1,clrA0,clrB0,rowDec);
  253.         }
  254.       } else {
  255.         ulong cA=(code1<<8) | code0;
  256.         RGBTriple clr;
  257.         clr.alpha=0;
  258.         RGB16toRGB24(cA,clr.red,clr.green,clr.blue);
  259.         cram8c1(iptr,clr,rowDec);
  260.       }
  261.       blockInc(xp,yp,rowDec);
  262.     }
  263.   }
  264. }
  265. /* \\\ */
  266.  
  267. /* /// "DecodeMSVC16to332()" */
  268. __asm void DecodeMSVC16to332(REG(a0) uchar *from,
  269.                              REG(a1) uchar *to,
  270.                              REG(d0) ulong width,
  271.                              REG(d1) ulong height,
  272.                              REG(d2) ulong encSize,
  273.                              REG(a2) struct MSVCData *spec)
  274. {
  275.   long exitflag=0;
  276.   ulong code0;
  277.   ulong code1;
  278.   ulong blockCnt=((width*height)>>4)+1;
  279.   long xp=0;
  280.   long yp=height-1;
  281.   ulong rowDec=width;
  282.  
  283.   while(!exitflag) {
  284.     code0=from[0];
  285.     code1=from[1];
  286.     from+=2;
  287.     blockCnt--;
  288.     if (((code1==0) && (code0==0) && !blockCnt) || (yp<0)) {
  289.       exitflag=1;
  290.       continue;
  291.     }
  292.     if ((code1>=0x84) && (code1<=0x87)) {
  293.       ulong skip=((code1-0x84)<<8)+code0;
  294.       blockCnt-=(skip-1);
  295.       while(skip--) blockInc(xp,yp,width);
  296.     } else {
  297.       uchar *iptr=(char *)(to+((yp*width)+xp));
  298.       if (code1<0x80) {
  299.         ulong cA, cB, cC, cD;
  300.         uchar cA0,cB0;
  301.         cB=get16pc(from);
  302.         cA=get16pc(from);
  303.         RGB16toColor(cA,cA0);
  304.         RGB16toColor(cB,cB0);
  305.         if (cB & 0x8000) {
  306.           uchar cA1, cB1;
  307.           cB=get16pc(from);
  308.           cA=get16pc(from);
  309.           RGB16toColor(cA,cA1);
  310.           RGB16toColor(cB,cB1);
  311.           cram8c4(iptr,code0,cA0,cA1,cB0,cB1,rowDec); iptr-=rowDec;
  312.           cB=get16pc(from);
  313.           cA=get16pc(from);
  314.           cD=get16pc(from);
  315.           cC=get16pc(from);
  316.           RGB16toColor(cA,cA0);
  317.           RGB16toColor(cB,cB0);
  318.           RGB16toColor(cC,cA1);
  319.           RGB16toColor(cD,cB1);
  320.           cram8c4(iptr,code1,cA0,cA1,cB0,cB1,rowDec);
  321.         } else {
  322.           cram8c2(iptr,code0,cA0,cB0,rowDec); iptr-=rowDec;
  323.           cram8c2(iptr,code1,cA0,cB0,rowDec);
  324.         }
  325.       } else {
  326.         uchar *iptr=to+yp*width+xp;
  327.         ulong cA=(code1<<8) | code0;
  328.         uchar clr;
  329.         RGB16toColor(cA,clr);
  330.         cram8c1(iptr,cA,rowDec);
  331.       }
  332.       blockInc(xp,yp,rowDec);
  333.     }
  334.   }
  335. }
  336. /* \\\ */
  337.  
  338. /* /// "DecodeMSVC16to332Dith()" */
  339. __asm void DecodeMSVC16to332Dith(REG(a0) uchar *from,
  340.                                  REG(a1) uchar *to,
  341.                                  REG(d0) ulong width,
  342.                                  REG(d1) ulong height,
  343.                                  REG(d2) ulong encSize,
  344.                                  REG(a2) struct MSVCData *spec)
  345. {
  346.   long exitflag=0;
  347.   ulong code0, code1;
  348.   ulong blockCnt=((width*height)>>4)+1;
  349.   long xp=0;
  350.   long yp=height-1;
  351.   ulong rowDec=width;
  352.  
  353.   while(!exitflag) {
  354.     code0=from[0];
  355.     code1=from[1];
  356.     from+=2;
  357.     blockCnt--;
  358.     if (((code1==0) && (code0==0) && !blockCnt) || (yp<0)) {
  359.       exitflag=1;
  360.       continue;
  361.     }
  362.     if ((code1>=0x84) && (code1<=0x87)) {
  363.       ulong skip=((code1-0x84)<<8)+code0;
  364.       blockCnt-=(skip-1);
  365.       while(skip--) blockInc(xp,yp,rowDec);
  366.     } else {
  367.       ulong r, g, b;
  368.       uchar *iptr=to+((yp*width)+xp);
  369.       if (code1<0x80) {
  370.         ulong cA, cB, cC, cD;
  371.         uchar cA0,cB0;
  372.         cB=get16pc(from);
  373.         cA=get16pc(from);
  374.         if (cB & 0x8000) {
  375.           ulong cA1, cB1;
  376.           RGB16toColor(cA,cA0);
  377.           RGB16toColor(cB,cB0);
  378.           cB=get16pc(from);
  379.           cA=get16pc(from);
  380.           RGB16toColor(cA,cA1);
  381.           RGB16toColor(cB,cB1);
  382.           cram8c4(iptr,code0,cA0,cA1,cB0,cB1,rowDec); iptr-=rowDec;
  383.           cB=get16pc(from);
  384.           cA=get16pc(from);
  385.           cD=get16pc(from);
  386.           cC=get16pc(from);
  387.           RGB16toColor(cA,cA0);
  388.           RGB16toColor(cB,cB0);
  389.           RGB16toColor(cC,cA1);
  390.           RGB16toColor(cD,cB1);
  391.           cram8c4(iptr,code1,cA0,cA1,cB0,cB1,rowDec);
  392.         } else {
  393.           ulong clr0a, clr0b, clr1a, clr1b;
  394.           long re=0, ge=0, be=0;
  395.           RGB16toRGB24(cA,r,g,b);
  396.           DitherGetRGB(r,g,b,re,ge,be,clr0a);
  397.           DitherGetRGB(r,g,b,re,ge,be,clr1a);
  398.           RGB16toRGB24(cB,r,g,b);
  399.           DitherGetRGB(r,g,b,re,ge,be,clr0b);
  400.           DitherGetRGB(r,g,b,re,ge,be,clr1b);
  401.           iptr[0]=(code0 & 0x01) ? (clr0b) : (clr0a);
  402.           iptr[1]=(code0 & 0x02) ? (clr1b) : (clr1a);
  403.           iptr[2]=(code0 & 0x04) ? (clr0b) : (clr0a);
  404.           iptr[3]=(code0 & 0x08) ? (clr1b) : (clr1a);
  405.           iptr-=rowDec;
  406.           iptr[0]=(code0 & 0x10) ? (clr1b) : (clr1a);
  407.           iptr[1]=(code0 & 0x20) ? (clr0b) : (clr0a);
  408.           iptr[2]=(code0 & 0x40) ? (clr1b) : (clr1a);
  409.           iptr[3]=(code0 & 0x80) ? (clr0b) : (clr0a);
  410.           iptr-=rowDec;
  411.           iptr[0]=(code1 & 0x01) ? (clr0b) : (clr0a);
  412.           iptr[1]=(code1 & 0x02) ? (clr1b) : (clr1a);
  413.           iptr[2]=(code1 & 0x04) ? (clr0b) : (clr0a);
  414.           iptr[3]=(code1 & 0x08) ? (clr1b) : (clr1a);
  415.           iptr-=rowDec;
  416.           iptr[0]=(code1 & 0x10) ? (clr1b) : (clr1a);
  417.           iptr[1]=(code1 & 0x20) ? (clr0b) : (clr0a);
  418.           iptr[2]=(code1 & 0x40) ? (clr1b) : (clr1a);
  419.           iptr[3]=(code1 & 0x80) ? (clr0b) : (clr0a);
  420.         }
  421.       } else {
  422.         ulong cA=(code1<<8) | code0;
  423.         ulong clr0, clr1;
  424.         long re=0, ge=0, be=0;
  425.         RGB16toRGB24(cA,r,g,b);
  426.         DitherGetRGB(r,g,b,re,ge,be,clr0);
  427.         DitherGetRGB(r,g,b,re,ge,be,clr1);
  428.         iptr[0]=clr0; iptr[1]=clr1; iptr[2]=clr0; iptr[3]=clr1; iptr-=rowDec;
  429.         iptr[0]=clr1; iptr[1]=clr0; iptr[2]=clr1; iptr[3]=clr0; iptr-=rowDec;
  430.         iptr[0]=clr0; iptr[1]=clr1; iptr[2]=clr0; iptr[3]=clr1; iptr-=rowDec;
  431.         iptr[0]=clr1; iptr[1]=clr0; iptr[2]=clr1; iptr[3]=clr0;
  432.       }
  433.       blockInc(xp,yp,rowDec);
  434.     }
  435.   }
  436. }
  437. /* \\\ */
  438.  
  439.